package fr.nts.framework.database.test.jpa.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.nts.framework.database.jpa.model.AJPAModel;

@Entity
@Table(name = "jpa_model_test")
public class JpaTestModel extends AJPAModel<Long>{
    
    private static final long serialVersionUID = 1L;
    
    private static final Logger log = LoggerFactory.getLogger(JpaTestModel.class);
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, length = 10, unique = true)
    private Long id;
    
    @Column(name = "code", nullable = false, length = 15, unique = true)
    private String code;
    
    @Column(name = "name", nullable = false, length = 55)
    private String name;
    
    
    
    public JpaTestModel(){
    	
    }

    public JpaTestModel(Long id){
    	this.id = id;
    }
    
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString(){
    	if(getLog().isDebugEnabled()){
	    	return new ToStringBuilder(this).append("id",
	                                                id)
	                                        .append("code",
	                                        		code)
	                                        .append("name",
	                                        		name)
	                                        .toString();
    	}else{
    		return super.toString();
    	}
    }


    /*
     * (non-Javadoc)
     * @see fr.nts.framework.database.jpa.model.AJPAObject#getLog()
     */
    @Override
    protected Logger getLog(){
    	return log;
    }
    
    
    // GETTER AND SETTER
	public Long getId(){
		return id;
	}

	public void setId(Long id){
		this.id = id;
	}

	public String getCode(){
		return code;
	}

	public void setCode(String code){
		this.code = code;
	}

	public String getName(){
		return name;
	}

	public void setName(String name){
		this.name = name;
	}
}